package untils;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Calendar;
import java.util.Random;

public class ClickSource implements SourceFunction<ClickEvent> {

    private String[] userArray = {"Money" , "Doller","Rmb","Maoyeye"};
    private String[] urlArray = {"./100w","200W","300w"};
    private Random random = new Random();

    private boolean running = true;

    @Override
    public void run(SourceContext<ClickEvent> ctx) throws Exception {

        while (running){
            ctx.collect(
                    new ClickEvent(
                            userArray[random.nextInt(userArray.length)],
                            urlArray[random.nextInt(urlArray.length)],
                            Calendar.getInstance().getTimeInMillis()
                    )
            );
            Thread.sleep(1000L);
        }
    }

    @Override
    public void cancel() {
        running = false;
    }
}
